import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [
  // 首页
  {
    path: '/',
    component: () => import('@/views/index/index.vue'),
  },
  {
    path: '/product/detail',
    component: () => import('@/views/index/product.vue'),
  },
  {
    path: '/search/index',
    component: () => import('@/views/index/search.vue'),
  },

  // 分类
  {
    path: '/classify/index',
    component: () => import('@/views/classify/index.vue'),
  },
  {
    path: '/classify/detail',
    component: () => import('@/views/classify/detail.vue'),
  },

  // 购物车
  {
    path: '/shopcar/index',
    component: () => import('@/views/shopcar/index.vue'),
  },

  // 生态
  {
    path: '/ecology/index',
    component: () => import('@/views/ecology/index.vue'),
  },

  // 我的
  {
    path: '/user/index',
    component: () => import('@/views/user/index.vue'),
  },
  {
    path: '/order/index',
    component: () => import('@/views/user/order/index.vue'),
  },
  {
    path: '/order/pay',
    component: () => import('@/views/user/order/pay.vue'),
  },
  {
    path: '/kpi/index',
    component: () => import('@/views/user/kpi.vue'),
  },
  {
    path: '/address/index',
    component: () => import('@/views/user/address.vue'),
  },
  {
    path: '/rank/index',
    component: () => import('@/views/user/rank.vue'),
  },
  {
    path: '/book/index',
    component: () => import('@/views/user/book.vue'),
  },
  {
    path: '/user/login',
    component: () => import('@/views/user/login.vue'),
  },
]

const router = createRouter({
  routes,
  history: createWebHashHistory(),
  scrollBehavior(to, from, savedPosition) {
    if (to.hash) {
      return {
        el: to.hash,
      }
    } else if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
})

export default router
